
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        ul {
            list-style-type: none;
        }

        .box {
            width: 400px;
            height: 300px;
            border: 1px solid #ccc;
            margin: 100px auto;
            overflow: hidden;
        }

        .hd {
            height: 45px;
        }

        .hd span {
            display: inline-block;
            width: 90px;
            background-color: pink;
            line-height: 45px;
            text-align: center;
            cursor: pointer;
        }

        .hd span.current {
            background-color: yellowgreen;
        }

        .bd li {
            height: 255px;
            background-color: yellowgreen;
            display: none;
        }

        .bd li.current {
            display: block;
            font-size: 36px;
        }
    </style>

</head>
<body>
<div class="box" id="box">
    <div class="hd">
        <span class="current">体育</span>
        <span>娱乐</span>
        <span>新闻</span>
        <span>综合</span>
    </div>
    <div class="bd">
        <ul>
            <li class="current">我是体育模块</li>
            <li>我是娱乐模块</li>
            <li>我是新闻模块</li>
            <li>我是综合模块</li>
        </ul>
    </div>
</div>
<script>
    var box = document.getElementById("box");
    var spans = box.getElementsByTagName("span");//上面的标签
    var lis = box.getElementsByTagName("li");//下面的盒子
    //点击span让当前的span高亮
    for (var i = 0; i < spans.length; i++) {
        spans[i].index = i;//给每一个span对象,添加自定义属性index === 保存当前的i(索引)
        spans[i].onclick = function () {
            //排他
            //干掉所有人
            for (var i = 0; i < spans.length; i++) {
                spans[i].className = "";
            }
            //留下我自己
            this.className = "current";
            //让下面对应的li也显示出来
            for (var i = 0; i < lis.length; i++) {
                lis[i].className = "";
            }
            //console.dir(this.index);
            var index = this.index;
            lis[index].className = "current";//根据索引,从li伪数组中找到对于的li对象

        };
    }
    /*var stu = {};
     stu.name = "zs";*/

</script>
</body>
</html>